package com.eleadmin.store.controller;

import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.store.entity.EntryBillSon;
import com.eleadmin.store.entity.SellSon;
import com.eleadmin.store.service.SellSonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 销售单子表
 * @author : Doman
 * @date : 2024-03-07 14:15:36
 * @version ：1.0
 */

@Api(tags = "销售单子表")
@RestController
@RequestMapping("/api/store/sellSon")
public class SellSonController extends BaseController {

    @Autowired
    private SellSonService sellSonService;

    @PreAuthorize("hasAuthority('store:sellSon:list')")
    //@ApiOperation("分页查询销售单子表")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, SellSon sellSon) throws Exception{
        return sellSonService.list(page, sellSon, getLoginUser());
    }

    @PreAuthorize("hasAuthority('store:sellSon:list')")
    //@ApiOperation("查询全部销售单子表")
    @GetMapping()
    public JsonResult list(SellSon sellSon){
        return sellSonService.list(sellSon, getLoginUser());
    }

    @PreAuthorize("hasAuthority('store:sellSon:list')")
    //@ApiOperation("根据id查询销售单子表")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return sellSonService.getById(id);
    }


    @PreAuthorize("hasAuthority('store:sellSon:save')")
    @OperationLog
    @ApiOperation(value ="添加销售单子表")
    @PostMapping()
    public JsonResult save(@RequestBody SellSon sellSon) {
        try {
            return sellSonService.save(sellSon, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('store:sellSon:update')")
    @OperationLog
    @ApiOperation(value ="修改销售单子表")
    @PutMapping()
    public JsonResult update(@RequestBody SellSon sellSon) {
        try {
            return sellSonService.update(sellSon, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('store:sellSon:remove')")
    @OperationLog
    @ApiOperation(value ="删除销售单子表")
    @PutMapping("remove")
    public JsonResult remove(@RequestBody SellSon sellSon) {
        try {
            return sellSonService.remove(sellSon, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
